package com.threeti.mecool.shared.util;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

import com.threeti.jiayusms.framework.util.Lists;

public abstract class AbstractTreeNode<T> implements Serializable {

  private T id;

  private String name;
  
  private AbstractTreeNode<T> parent;
  
  private List<AbstractTreeNode<T>> childs = Lists.newArrayList();

  public AbstractTreeNode(T id, String name) {
    super();
    this.id = id;
    this.name = name;
  }

  public T getId() {
    return id;
  }

  public String getName() {
    return name;
  }

  public AbstractTreeNode<T> getParent() {
    return parent;
  }

  public void setParent(AbstractTreeNode<T> parent) {
    this.parent = parent;
  }

  public List<AbstractTreeNode<T>> getChilds() {
    return Collections.unmodifiableList(childs);
  }

  public AbstractTreeNode<T> addChild(AbstractTreeNode<T> node) {
    node.setParent(this);
    childs.add(node);
    return this;
  }

  protected AbstractTreeNode() {
  }  
  
}
